
package de.syfy.project.game.base;

import java.util.Iterator;

/**
 * Talentbaum-Klasse
 *
 * @author felixspielmann
 */
public class TalentTree {

    /**
     * lvl0, immer vorhanden. => root
     */
    private TalentTreeNode lvl0;

    /**
     * Iteratorschema zur besseren verwendung des TalentBaumes
     * @return spezieller Talentbaum Iterator
     */
    public TalentTreeIterator iterator() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Talent findTalent(String name){
        Talent ret = null;
        TalentTreeIterator iter = this.iterator();         
            while(iter.hasNext()){
                if(iter.node.left.name.equals(name)){
                    ret = iter.node.getLeft();
                    break;
                }else if (iter.node.mid.name.equals(name)){
                    ret = iter.node.getMid();
                    break;
                }else if(iter.node.right.name.equals(name)){
                    ret = iter.node.getRight();
                    break;
                } else{
                    iter.next();
                }
            }
            return ret;
    }
    
    
    /**
     * Lvl des Baums... eigentliche Baumknoten
     * vom Prinzip her eine Doppelverkettete Liste mit einzelnen "Ablegern" / "Blättern"
     */
    private class TalentTreeNode {
        
        /**
         * Vorgänger
         */
        private TalentTreeNode predecessor;
        /**
         * Nachfolger
         */
        private TalentTreeNode successor;
        
        private Talent left;
        private Talent mid;
        private Talent right;
        
        public TalentTreeNode(TalentTreeNode pre , TalentTreeNode suc , 
                Talent left, Talent mid, Talent right){
            
            this.predecessor = pre;
            this.successor = suc;
            this.left = left;
            this.mid = mid; 
            this.right = right;
        }
        
        public TalentTreeNode() { this(null,null,null,null,null); }

        public Talent getLeft() {
            return left;
        }

        public Talent getMid() {
            return mid;
        }

        public TalentTreeNode getPredecessor() {
            return predecessor;
        }

        public Talent getRight() {
            return right;
        }

        public TalentTreeNode getSuccessor() {
            return successor;
        }
        
        
    }
    
    /**
     * Auswählbare Talente
     */
    private class Talent {
        
        private String name;
        /**
         * Faktor mit dem der Skill multipliziert wird...
         */
        private int learned;
        private int possible;
        
        Skill skill;

        public Talent() {
   
            
        }
              
        
        
    }
    
    public class TalentTreeIterator implements Iterator<TalentTreeNode> {

        TalentTreeNode node = lvl0;
        
        public TalentTreeIterator() {
        }

        @Override
        public boolean hasNext() {
            return (node.successor != null);
        }

        @Override
        public TalentTreeNode next() {
            this.node = node.successor;
            return node;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
}
